<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    /*
    boolean向数字类型转换时，true会转换成1
    flase 转换为0
    UNdefined向数字转换成NaN
    NULL向数字转换成0
    可以使用parseInt，parseFloat，Number来实现
    将字符串转换为数字类型，如果字符串是一个非
    纯数字字符的祖父穿，转换结果就是NaN;
    */
    var b1 = true;
    var b2 = false;
    var result1 = b1 + 0;
    var result2 = b2 + 0;
    document.write(result1 + "<br/>", result2 + "<br/>");

    var u1 = undefined;
    var result3 = Number(u1);
    document.write(result3 + "<br/>");

    var n1 = null;
    var result4 = Number(n1);
    document.write(result4 + "<br/>");

    var str1 = "123";
    var str2 = "abc123";
    //字符串向数字转换
    var result5 = parseInt(str1);
    document.write(result5 + "<br/>");
    var result6 = parseInt(str2);
    document.write(result6);


</script>
</html>